package com.searchdemo.thread;

import java.util.concurrent.CountDownLatch;

public class Test {
	
	/* Thread-0 start
		Thread-0将耗时11196ms 还有
		Thread-1 start
		Thread-1将耗时13332ms 还有
		Thread-0结束. 11196ms 还有1 个线程
		Thread-1结束. 13332ms 还有0 个线程
		all finished
	 */
	public static void main1(String[] args) {
		int total = 2;
		CountDownLatch threadsSignal = new CountDownLatch(total);
		for(int i=0;i<total;i++){
			Processor pro = new Processor(threadsSignal);
			pro.start();
		}
		try {
			threadsSignal.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println("all finished");
	}
	
	public static void main(String[] args) {
		int total = 2;
		for(int i=0;i<total;i++){
			Processor pro = new Processor();
			pro.start();
		}
		System.out.println("all finished");
	}

}
